* ==============================================================================
* Date: Dec 13, 2024
* Project: Health and anti-immigration attitudes
*
* This do file contains codes for variabe management:
*		First, it loads and reduces data from each round. 
* 		Second, it then merges (appends) them.
*		Third, it creates the main independent and dependent variables.
*		Fourth, it creates the control variables.
* ==============================================================================


					* Setup STATA
					* ===========
**# Bookmark #1

* Install packages
* ssc install oesch
* ssc install valtovar
* ssc install asgen


set more off

clear all

* Insert your working directory here:
global PATH "..."
cd $PATH

					* Download ESS data by rounds 
					* ===========================

/* Datasets pulled from the ESS Data Portal on July 25, 2024 
https://ess.sikt.no/en/?tab=overview */

					* Clean ESS1
					*===========
					
* ESS1 - integrated file, edition 6.7			
use data_ess/ESS1e06_7.dta, clear

* Keep variables used in the analysis

#delimit ;
keep 	essround cntry idno dweight pspwght pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr blgetmg gndr agea marital rlgdgr domicil
		edulvla eduyrs eisced* nacer1 
		wrkctr iscoco emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnt hincsrc hincfel
		edulvlfa emprf14 edulvlma emprm14
		tvpol rdpol nwsppol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		imbleco imtcjob imwbcrm noimbro acetalv eimpcnt gvrfgap
		imsmrgt
		;
#delimit cr

save data_hlthmigr/ess1.dta, replace


					* Clean ESS2
					*===========

* ESS2 - integrated file, edition 3.6 (Italy not included)
clear all
use data_ess/ESS2e03_6.dta, clear

* Keep variables used in the analysis

#delimit ;
keep 	essround cntry idno dweight pspwght pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr blgetmg gndr agea marital rlgdgr domicil
		edulvla eduyrs eisced* nacer1 
		wrkctr iscoco emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnt hincsrc hincfel
		edulvlfa emprf14 edulvlma emprm14
		tvpol rdpol nwsppol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		;
#delimit cr

save data_hlthmigr/ess2.dta, replace


					* Clean ESS3
					*===========

* ESS3 - integrated file, edition 3.7 (Latvia and Romania not included)
clear all
use data_ess/ESS3e03_7.dta, clear

* Keep variables used in the analysis

#delimit ;
keep 	essround cntry idno dweight pspwght pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr blgetmg gndr agea maritala rlgdgr domicil
		edulvla eduyrs eisced* nacer11 
		wrkctr iscoco emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnt hincsrca hincfel
		edulvlfa emprf14 edulvlma emprm14
		tvpol rdpol nwsppol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		
		fltdpr cldgng slprl wrhpp fltlnl enjlf fltsd
		optftr enrglot lchshcp wrbknrm
		;
#delimit cr

save data_hlthmigr/ess3.dta, replace


					* Clean ESS4
					*===========

* ESS4 - integrated file, edition 4.6 (Austria and Lithuania not included)
clear all
use data_ess/ESS4e04_6.dta, clear

* Keep variables used in the analysis

#delimit ;
keep 	essround cntry idno dweight pspwght pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr imrccon
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr blgetmg gndr agea maritala rlgdgr domicil
		edulvla eduyrs eisced* nacer11 
		wrkctr iscoco emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnta hincsrca hincfel
		edulvlfa emprf14 edulvlma emprm14
		tvpol rdpol nwsppol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		imsclbn lkuemp lknemny lknhlcn
		;
#delimit cr

save data_hlthmigr/ess4.dta, replace



					* Clean ESS5
					*===========

* ESS5 - integrated file, edition 3.5 (Austria not included)					
clear all
use data_ess/ESS5e03_5.dta, clear

* Keep variables used in the analysis

#delimit ;
keep 	essround cntry idno dweight pspwght pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr blgetmg gndr agea marsts maritalb rlgdgr domicil
		edulvlb eduyrs eisced* nacer2 
		wrkctr iscoco emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnta hincsrca hincfel
		edulvlfb emprf14 edulvlmb emprm14
		tvpol rdpol nwsppol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		fltlnla
		;
#delimit cr

save data_hlthmigr/ess5.dta, replace


					* Clean ESS6
					*===========

* ESS6 - integrated file, edition 2.6					
use data_ess/ESS6e02_6.dta, clear

* Keep variables used in the analysis

#delimit ;
keep 	essround cntry idno dweight pspwght pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr blgetmg gndr agea marsts maritalb rlgdgr domicil
		edulvlb eduyrs eisced* nacer2 
		wrkctr isco08 emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnta hincsrca hincfel
		edulvlfb emprf14 edulvlmb emprm14
		tvpol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		fltdpr cldgng slprl wrhpp fltlnl enjlf fltsd
		optftr enrglot lchshcp wrbknrm
		;
#delimit cr

save data_hlthmigr/ess6.dta, replace



					* Clean ESS7
					*===========

* ESS7 - integrated file, edition 2.3					
clear all
use data_ess/ESS7e02_3.dta, clear

#delimit ;
keep 	essround cntry idno dweight pspwght pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr blgetmg gndr agea marsts maritalb rlgdgr domicil
		edulvlb eduyrs eisced* nacer2 
		wrkctr isco08 emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnta hincsrca hincfel
		edulvlfb emprf14 edulvlmb emprm14
		tvpol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		fltdpr cldgng slprl wrhpp fltlnl enjlf fltsd
		imbleco imtcjob imwbcrm noimbro acetalv eimpcnt gvrfgap
		hltprhc hltprca hltprhb hltprbp hltpral hltprbn hltprpa 
		hltprpf hltprsd hltprsc hltprsh hltprdi hltprnt 
		hltphhc hltphhb hltphbp hltphal hltphbn hltphpa 
		hltphpf hltphsd hltphsc hltphsh hltphdi hltphnt
		medtrun medtrnp medtrnt medtroc medtrnl medtrwl 
		medtrnaa medtroth medtrnu
		alcfreq alcwkdy alcwknd alcbnge
		cgtsmke cgtsday 
		etfruit eatveg dosprt
		fnsdfml
		;
#delimit cr

save data_hlthmigr/ess7.dta, replace


					* Clean ESS8
					*===========

* ESS8 - integrated file, edition 2.3					
clear all
use data_ess/ESS8e02_3.dta, clear

#delimit ;
keep 	essround cntry idno dweight pspwght pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr blgetmg gndr agea marsts maritalb rlgdgr domicil
		edulvlb eduyrs eisced* nacer2 
		wrkctr isco08 emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnta hincsrca hincfel
		edulvlfb emprf14 edulvlmb emprm14
		nwspol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		imsclbn lkuemp lknemny gvrfgap		
		;
#delimit cr

save data_hlthmigr/ess8.dta, replace


					* Clean ESS9
					*===========
					
* ESS9 - integrated file, edition 3.2
clear all
use data_ess/ESS9e03_2.dta, clear

#delimit ;
keep 	essround cntry idno dweight pspwght pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr blgetmg gndr agea marsts maritalb rlgdgr domicil
		edulvlb eduyrs eisced* nacer2 
		wrkctr isco08 emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnta hincsrca hincfel
		edulvlfb emprf14 edulvlmb emprm14
		nwspol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		;
#delimit cr

save data_hlthmigr/ess9.dta, replace


					* Clean ESS10
					*============

* ESS10 - integrated file, edition 3.2
* missing: blgetmg
clear all
use data_ess/ESS10.dta, clear

#delimit ;
keep 	essround cntry idno dweight pspwght pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr gndr agea marsts maritalb rlgdgr domicil
		edulvlb eduyrs eisced* nacer2 
		wrkctr isco08 emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnta hincsrca hincfel
		edulvlfb emprf14 edulvlmb emprm14
		nwspol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		;
#delimit cr

save data_hlthmigr/ess10.dta, replace


					* Clean ESS11
					*============

* ESS11 - integrated file, edition 1.0
* missing: pspwght blgetmg
clear all
use data_ess/ESS11.dta, clear

#delimit ;
keep 	essround cntry idno dweight  pweight
		health dsbld hlthhmp happy
		imbgeco imueclt imwbcnt imsmetn imdfetn impcntr
		stfhlth stflife stfeco stfdem
		brncntr facntr mocntr gndr agea marsts maritalb rlgdgr domicil
		edulvlb eduyrs eisced* nacer2 
		wrkctr isco08 emplrel emplno
		uempla uempli uemp3m uemp12m uemp5yr mbtru 
		hinctnta hincsrca hincfel
		edulvlfb emprf14 edulvlmb emprm14
		nwspol
		trstplt trstprl trstlgl ppltrst
		clsprty lrscale polintr freehms
		impsafe ipstrgv imptrad ipeqopt ipudrst ipcrtiv
		;
#delimit cr

save data_hlthmigr/ess11.dta, replace

					* Append
					*=======

					
clear all
use data_hlthmigr/ESS1.dta, clear

forv x = 2(1)11 {
	append using "data_hlthmigr/ess`x'.dta"
}
save data_hlthmigr/hlthmigr.dta, replace


*** Keep countries (European Economic Area) and cases needed

drop if cntry=="AL" | cntry=="IL" | cntry=="ME" | cntry=="RS" | cntry=="RU" | cntry=="TR" | cntry=="UA" | cntry=="XK" | cntry=="MK"

drop if (agea>105 | agea <15) & agea<. // 13 observations


*** Generate analytical weights 
gen anweight=pspwght*pweight
replace anweight = dweight*pweight if anweight==. // pspwght missing for round 11, and for EE (n=1542)

*** Define ID variables

encode cntry, gen(cntryc) // Country ID
egen atcntry = tag(cntryc)

egen atround = tag(essround)

recode essround (1 = 2002) (2 = 2004) (3 = 2006) (4 = 2008) (5 = 2010) (6 = 2012) (7 = 2014) (8 = 2016) (9 = 2018) (10 = 2020) (11 = 2023), gen(year) 
lab var year "Year"

egen id = group(essround cntryc idno)
lab var id "Individual-level ID"

egen cntryround=group(cntryc essround)
lab var cntryround "Country-round"

save data_hlthmigr/hlthmigr.dta, replace


					* Main dependent and independent variables
					* ========================================
**# Bookmark #2				


*** Dependent variables

** Label variables
lab var imueclt		"Immigration good for country's culture"
lab var imbgeco		"Immigration good for country's economy"
lab var imwbcnt		"Immigrants make country better place to live"

gen imuecltr = 10-imueclt
gen imbgecor = 10-imbgeco
gen imwbcntr = 10-imwbcnt

lab var imuecltr		"Immigration bad for country's culture"
lab var imbgecor		"Immigration bad for country's economy"
lab var imwbcntr		"Immigrants make country worse place to live"

lab def imuecltr	10 "Cultural life undermined" 0 "Cultural life enriched"
lab def imbgecor	10 "Bad for the economy" 0 "Good for the economy"
lab def imwbcntr	10 "Worse place to live" 0 "Better place to live"

lab val imuecltr imuecltr
lab val imbgecor imbgecor
lab val imwbcntr imwbcntr

lab var imsmetn 	"Restrict immigrants from same race/ethnicity"
lab var imdfetn 	"Restrict immigrants from different race/ethnicity"
lab var impcntr		"Restrict immigrants from poorer countries outside Europe"


* Recode migrants drain public services variable
/* Round 4 has a very similarly worded variable but with different varname. 
The distribution of the two variables is very close also. Merge the two. */

replace imbleco = imrccon if essround == 4

gen imblecor=10-imbleco
lab var imblecor "Immigrants drain public services"
lab def imblecor 0 "Migrants put in more" 10 "Migrants take out more", modify
lab val imblecor imblecor

recode imbleco 	(5 6 7 8 9 10 = 0 "Migrants put in more") ///
				(0 1 2 3 4 = 1 "Migrants take out more") ///
				, gen(imblecor2)
lab var imblecor2 "Immigrants drain public services"


** Create anti-migration index

alpha imbgeco imueclt imwbcnt, gen(migr)
lab var migr "Support for immigration"
lab def migr 0 "Low" 10 "High"
lab val migr migr

gen migrw2 = .
replace migrw2 = 0 if migr >= 5.333333
replace migrw2 = 1 if migr < 5.333333
lab var migrw2 "Worried about immigration"
lab def migrw2 0 "Not worried" 1 "Worried", replace
lab val migrw2 migrw2

su migr, meanonly 
gen migr100 = 100*(migr - r(min))/(r(max) - r(min))
lab var migr100 "Support for immigration"

qui su migr100, d
gen double migrw100=r(max)-migr100+r(min)
lab var migrw100 "Worried about immigration"


alpha imsmetn imdfetn impcntr, gen(mrestr)
lab var mrestr "Restrict immigration"
lab def mrestr 1 "Allow many to come" 4 "Allow none to come"
lab val mrestr mrestr

su mrestr, meanonly 
gen migrr100 = 100*(mrestr - r(min))/(r(max) - r(min))
lab var migrr100 "Restrict immigration"


*  Racial/ethnic minorities in living area
lab var acetalv "Perceived prevalence of racial/ethnic minorities in living area"
cap lab drop acetalv
lab def acetalv 1 "Almost nobody" 2 "Some" 3 "Many"
lab val acetalv acetalv

recode acetalv	(1 2 = 0 "Some") ///
				(3 = 1 "Many") ///
				, gen(acetalv2)
lab var acetalv2 "Perceived prevalence of racial/ethnic minorities in living area: many"

* imsclbn
recode imsclbn 	(4 5	= 2 "Until they become citizens or forever") ///
				(3 = 1 "Until they worked and paid taxes at least a year") ///
				(1 2 = 0 "Max for a year, whether or not have worked") ///
				, gen (imsclbn3)
lab var imsclbn3 "Restrict immigrants' social rights"

* imsclbn
recode imsclbn 	(4 5 = 1 "Until they become citizens or forever") ///
				(1 2 3 = 0 "Max until they paid taxes at least a year") ///
				, gen (imsclbn2)
lab var imsclbn2 "Restrict immigrants' social rights"

* lknhlcn
lab var lknhlcn "Fear of losing access to public health services"



* Generate country-level means and SD
* Mean self-rated health 
bysort cntryc: asgen c_migr_m = migr, w(anweight) 
lab var c_migr_m "Average support for immigration"
egen c_migr_sd = sd(migr), by(cntryc)
lab var c_migr_sd "Standard deviation of support for immigration"

bysort cntryc: asgen c_migrw100_m = migrw100, w(anweight)
lab var c_migrw100_m "Average immigration worry score"
egen c_migrw100_sd = sd(migrw100), by(cntryc)
lab var c_migrw100_sd "Standard deviation of support for immigration"


*** Main independent variable
lab var health "Self-rated health"

** Recode health variable
* Step 1
recode health 	(1 = 0 "Very good") ///
				(2 = 1 "Good") ///
				(3 = 2 "Fair") ///
				(4 = 3 "Bad") ///
				(5 = 4 "Very bad") ///
				, gen(hlth5)
lab var hlth5 "Self-rated health"

* Step 2
recode health 	(1 2 = 0 "Health: Good") ///
				(3 4 5 = 1 "Health: Bad") ///
				, gen(hlth2a)				
lab var hlth2a "Self-rated health: Bad"
lab def hlth2a 0 "Good" 1 "Bad", modify
lab val hlth2a hlth2a

* Step 3
recode health 	(1 2 3 = 0 "Health: Good") ///
				(4 5 = 1 "Health: Bad") ///
				, gen(hlth2b)				
lab var hlth2b "Self-rated health"
lab def hlth2b 0 "Good" 1 "Bad", modify
lab val hlth2b hlth2b

** Generate country-level means and standard errors
* Share of those reporting fair, bad or very bad health

bysort cntryc: asgen c_badhlth_pc = hlth2a*100, w(anweight)
lab var c_badhlth_pc "Weighted share of respondents reporting bad self-rated health (%)"
tabstat c_badhlth_pc, by(cntry)


* Mean self-rated health 
bysort cntryc: asgen c_health_m = hlth5, w(anweight) 
lab var c_health_m "Average self-rated health"
egen c_health_sd = sd(hlth5), by(cntryc)
lab var c_health_sd "Standard deviation of average self-rated health"

save data_hlthmigr/hlthmigr.dta, replace


** Other health-related variables 

recode hlthhmp	(1 2 = 1 "Hampered by illness: Yes") ///
				(3 = 0 "Hampered by illness: No") ///
				, gen(hlthhmp2)
lab var hlthhmp2 "Hampered in daily activities by illness"


recode etfruit 	(1 2 = 0 "At least 2-3 times a day") ///
				(3 = 1 "Once a day") ///
				(4 5 6 7 = 2 "Less than once a day") ///
				, gen(etfruit3)
lab var etfruit3 "How often eat fruit"
tab etfruit3

recode eatveg 	(1 2 = 0 "At least 2-3 times a day") ///
				(3 = 1 "Once a day") ///
				(4 5 6 7 = 2 "Less than once a day") ///
				, gen(eatveg3)
lab var eatveg3 "How often eat vegetables or salad"
tab eatveg3

recode alcfreq 	(1 2 = 2 "Several times a week") ///
				(3 4 5 = 1 "At least once a month") ///
				(4 5 6 7 = 0 "Less than once a month") ///
				, gen(alcfreq3)
lab var alcfreq3 "How often drink alcohol"
tab alcfreq3

recode dosprt 	(0 1 2 = 2 "Twice or less a week") ///
				(3 4 5 = 1 "3-5 times a week") ///
				(6 7 = 0 "At least six times a week") ///
				, gen(dosprt3)
lab var dosprt3 "How often do sport"
tab dosprt3

recode alcbnge 	(1 2 = 3 "Daily or weekly") ///
				(3 = 2 "Monthly") ///
				(4 5 = 1 "Less than monthly or never") ///
				, gen(alcbnge3)
lab var alcbnge3 "Frequency of binge drinking"

alpha etfruit3 eatveg3 dosprt3 alcbnge3, gen(hlthbhv3)
lab var hlthbhv3 "Unhealthy lifestyle scale"

gen hltpsum = hltprhc + hltprhb + hltprbp + hltpral + hltprbn + hltprpa + hltprpf + hltprsd + hltprsc + hltprsh + hltprdi
gen hltprm2 = .
replace hltprm2 = 1 if hltpsum > 1 & hltpsum < 12 
replace hltprm2 = 0 if hltpsum == 0 | hltpsum == 1
lab var hltprm2 "Multiple health problems in past 12 months"
lab def hltprm2 0 "Multiple health problems: No" 1 "Multiple health problems: Yes"
lab val hltprm2 hltprm2

* Satisfaction w health system

gen stfhlthr = 10-stfhlth
lab var stfhlthr "Dissatisfied with the health system"
lab def stfhlthr 0 "Satisfied w health syst" 10 "Dissatisfied w health syst", modify
lab val stfhlthr stfhlthr
tab stfhlthr

* medtrun

recode medtrun	(1 = 1 "Unmet medical needs: Yes") ///
				(2 = 0 "Unmet medical needs: No") ///
				, gen(medtrunr)
lab var medtrunr "Unmet medical need in last year"



					* Mediators
					* =========
**# Bookmark #3				
				

* Generate political trust scale

alpha trstplt trstprl trstlgl, gen(trst)
lab var trst "Trust in political institutions"
lab def trst 0 "Low" 10 "High"
lab val trst trst

gen trstr = 10-trst
lab var trstr "Distrust in political institutions"
lab def trstr 0 "No distrust" 10 "Much distrust", modify
lab val trstr trstr
tab trstr

egen trstr2 = cut(trstr), at(0, 5, 10) icodes
lab var trstr2 "Low trust"
lab def trstr2 0 "High trust" 1 "Low trust"
lab val trstr2 trstr2
tab trstr2

gen trstpltr = 10-trstplt
gen trstprlr = 10-trstprl
gen trstlglr = 10-trstlgl
gen ppltrstr = 10-ppltrst

lab var trstpltr "Distrust in politicians"
lab var trstprlr "Distrust in parliament"
lab var trstlglr "Distrust in legal system"
lab var ppltrstr "Diminished interpersonal trust"



					* Control variables
					* =================
**# Bookmark #4


					
*** Gender
recode gndr		(1 = 1 "Gender: Men") ///
				(2 = 0 "Gender: Women") ///
				, gen(gndr2)
lab var gndr2 "Gender: Men"
tab gndr gndr2

*** Consolidated marital status variable

* Rounds 5-10
gen mrtsts4 = .
replace mrtsts4 = 1 if maritalb==1 | maritalb==2
replace mrtsts4 = 2 if maritalb==3 | maritalb==4
replace mrtsts4 = 3 if maritalb==5
replace mrtsts4 = 4 if maritalb==6
lab var mrtsts4 "Marital status"

lab def mrtsts4 1 "Married or partnered" 2 "Divorced or separated" 3 "Widowed or partner died" 4 "Never married or partnered", replace
lab val mrtsts4 mrtsts4

* Rounds 1-2
replace mrtsts4 = 1 if marital==1
replace mrtsts4 = 2 if marital==2 | marital==3
replace mrtsts4 = 3 if marital==4
replace mrtsts4 = 4 if marital==5

* Rounds 3-4
/* Note, the Estonian data from the question block on marital status 
has been omitted from the integrated file; see ESS documentation. */
replace mrtsts4 = 1 if maritala==1 | maritala==2
replace mrtsts4 = 2 if maritala==3 | maritala==4 | maritala==5 | maritala==7
replace mrtsts4 = 3 if maritala==6 | maritala==8
replace mrtsts4 = 4 if maritala==9



*** Income
/*
The ESS used a different coding scheme for the income variable in the first three rounds, with 12 income categories, and using a unified cut-off template for each country. From round 4 on, there are only 10 categories, and the categories represent cut-offs that take into consideration the national distribution of income. The categories from ESS4 on correspond to the household's position in the income distribution. The categories in rounds 1-3 do not, and are skewed towards the upper middle, with fewer values around the tails of the distribution. We simply collapse the bottom and the top two income categories to create an income variable with 10 categories in the first 3 rounds. This means that the income variable is not comparable through time. This variable can only be used as a control variable in cross-sectional models.

Some countries have been excluded, for example, Bulgaria, Cyprus, Slovakia used different coding, and were ommited from the integrated data file. See ESS data documentation for details.
*/

recode hinctnt (1 2 = 1) (3 = 2) (4 = 3) (5 = 4) (6 = 5) (7 = 6) (8 = 7) (9 = 8) (10 = 9) (11 12 = 10), gen(hinctntb)
replace hinctntb = hinctnta if essround > 3
lab var hinctntb "Household's total net income"
lab val hinctntb labels459


*** Subjective income status
recode hincfel	(1 2 = 0 "Difficult to live on present income: No") ///
				(3 4 = 1 "Difficult to live on present income: Yes") ///
				, gen(hincfel2)
lab var hincfel2 "Difficult to live on present income"
tab hincfel hincfel2

*** Likely financial hardship in near future 
recode lknemny	(1 2 = 0 "Low risk of financial strain") ///
				(3 4 = 1 "High risk of financial strain") ///
				, gen(lknemny2)
lab var lknemny2 "Economic insecurity"
tab lknemny lknemny2

*** Social benefits
** Main income: Social benefits
* Rounds 2-9
recode hincsrca	(1 2 3 4 7 8 = 0 "Main income: Wages, investments, pensions") ///
				(5 6 = 1 "Main income: Social benefits") ///
				, gen(hincsrc2a)
lab var hincsrc2a "Main source of household income: Social benefits"

* Round 1
replace hincsrc2a = 0 if hincsrc == 1 | hincsrc == 2 | hincsrc == 3 | hincsrc == 6 | hincsrc == 7
replace hincsrc2a = 1 if hincsrc == 4 | hincsrc == 5
tab hincsrc2a essround, column nof

** Main income: Main income: Wages and investments w/o pensions
* Rounds 2-9
recode hincsrca	(1 2 3 7 = 1 "Main income: Wages and investments") ///
				(4 5 6 8 = 0 "Main income: Social benefits and pension") ///
				, gen(hincsrc2b)
lab var hincsrc2b "Main source of household income: Social benefits and pension"
tab hincsrc2b

* Round 1
replace hincsrc2b = 1 if hincsrc == 1 | hincsrc == 2 | hincsrc == 6 | hincsrc == 7
replace hincsrc2b = 0 if hincsrc == 3 | hincsrc == 4 | hincsrc == 5
tab hincsrc2b essround, column nof


*** Domicile

recode domicil	(1 2 = 1 "Big city or suburb") ///
				(3 = 2 "Small city") ///
				(4 5 = 3 "Village or farm") ///
				, gen(domicil3)
lab var domicil3 "Domicile"
tab domicil3 essround


*** Recode born in country 0-1

recode brncntr	(1 = 0 "Born in another country: No") ///
				(2 = 1 "Born in another country: Yes") ///
				, gen(brncntr2)
lab var brncntr2 "Respondent born in another country"
tab brncntr brncntr2


*** Belong to ethnic minority
* Data missing for round 10 & 11
recode blgetmg	(1 = 1 "Belong to ethnic minority: Yes") ///
				(2 = 0 "Belong to ethnic minority: No") ///
				, gen(blgetmg2)
lab var blgetmg2 "Belong to ethnic minority"
tab blgetmg blgetmg2


*** Generate variable indicating immigrant background

gen migrfam =.
replace migrfam = 1 if brncntr == 2 | mocntr == 2 | facntr == 2
replace migrfam = 0 if brncntr == 1 & mocntr == 1 & facntr == 1
lab var migrfam "Migrant family background"
lab def migrfam 0 "No" 1 "Yes"
lab val migrfam migrfam
tab migrfam


*** Type of work contract
lab var wrkctra "Type of work contract"

*** Relabel currently unemployed 0-1
lab def uempla 0 "Not unemployed", replace 
lab def uempla 1 "Unemployed, actively looking for a job", add
lab val uempla uempla

* unemployed 3m

recode uemp3m 	(1 = 1 "Yes") ///
				(2 = 0 "No") ///
				, gen(uemp3m2)
lab var uemp3m2 "Ever unemployed for 3+ months"
tab uemp3m uemp3m2

* unemployed 5y

recode uemp5yr 	(1 = 1 "Yes") ///
				(2 = 0 "No") ///
				, gen(uemp5yr2)
lab var uemp5yr2 "Unemployed in last 5 years"
tab uemp5yr uemp5yr2


*** Education
** Rounds 5-10
recode eisced (1 2=1 "Low") (3 4 5=2 "Medium") (6 7=3 "High") (55=.) if essround>4, gen(edulevel)
lab var edulevel "Education level"
tab edulevel essround

** Rounds 1-4
recode edulvla (1 2 = 1 "Low") (3 4 = 2 "Medium") (5 = 3 "High") (55=.) if essround<5, gen(edulevel2)
replace edulevel = edulevel2 if essround < 5
drop edulevel2
tab edulevel essround, column nof 


*** Generate consolidated political news-consumption variable

* step 1: recode tvpol into dummy

gen tvpol2 =.
replace tvpol2 = 0 if tvpol==0 | tvpol==1
replace tvpol2 = 1 if tvpol>=2 & tvpol<=7
replace tvpol2 =. if essround>7
lab var tvpol2 "TV watching, news/politics/current affairs on average weekday"
lab def tvpol2 0 "Less than 0.5 hours" 1 "At least 0.5 hours", replace
lab val tvpol2 tvpol2
bysort essround: su tvpol
bysort essround: su tvpol2
tab tvpol2

* step 2: recode rdpol into dummy

gen rdpol2 =.
replace rdpol2 = 0 if rdpol==0 | rdpol==1
replace rdpol2 = 1 if rdpol>=2 & rdpol<=7
replace rdpol2 =. if essround>5
lab var rdpol2 "Radio listening, news/politics/current affairs on average weekday"
lab def rdpol2 0 "Less than 0.5 hours" 1 "At least 0.5 hours"
lab val rdpol2 rdpol2
bysort essround: su rdpol
bysort essround: su rdpol2
tab rdpol2

* step 3: recode nwsppol into dummy

gen nwsppol2 =.
replace nwsppol2 = 0 if nwsppol==0 | nwsppol==1
replace nwsppol2 = 1 if nwsppol>=2 & nwsppol<=7
replace nwsppol2 =. if essround>5
lab var nwsppol2 "Newspaper reading, politics/current affairs on average weekday"
lab def nwsppol2 0 "Less than 0.5 hours" 1 "At least 0.5 hours"
lab val nwsppol2 nwsppol2
bysort essround: su nwsppol
bysort essround: su nwsppol2
tab nwsppol2

* step 4: consolidate tvpol rdpol nwsppol

gen nwspol1 =.
replace nwspol1 = 0 if tvpol2==0 & rdpol2==0 & nwsppol2==0
replace nwspol1 = 1 if tvpol2==1 | rdpol2==1 | nwsppol2==1
replace nwspol1 = 0 if tvpol2==0 & essround==6 
replace nwspol1 = 0 if tvpol2==0 & essround==7
lab var nwspol1 "News about politics and current affairs, watching, reading or listening (w1-7)"
lab def nwspol1 0 "Less than 0.5 hours" 1 "At least 0.5 hours"
lab val nwspol1 nwspol1
bysort essround: su nwspol1

* step 5: recode nwspol into dummy

gen nwspol1b =.
replace nwspol1b = 0 if nwspol>=0 & nwspol<30 
replace nwspol1b = 1 if nwspol>=30 & nwspol<1441
replace nwspol1b =. if essround<8
lab var nwspol1b "News about politics and current affairs, watching, reading or listening (w8-9)"
lab def nwspol1b 0 "Less than 0.5 hours" 1 "At least 0.5 hours"
lab val nwspol1b nwspol1b
bysort essround: su nwspol1b

* step 6: consolidate nwspol1 nwspol2 to cover all waves

generate nwspol2 = min(nwspol1, nwspol1b)
lab def nwspol2 0 "News consumption: Less than 0.5 hours" 1 "News consumption: At least 0.5 hours", replace
lab val nwspol2 nwspol2
lab var nwspol2 "News consumption: At least 0.5 hours daily"
tab nwspol2

drop tvpol2 rdpol2 nwsppol2 nwspol1 nwspol1b

*** Feel close to any party
recode clsprty	(1 = 1 "Feel close to any party: Yes") ///
				(2 = 0 "Feel close to any party: No") ///
				, gen(clsprty2)
lab var clsprty2 "Feel close to any party"			
tab clsprty clsprty2		


* Interested in politics
gen polintrr = 5-polintr
lab var polintrr 	"Interested in politics"

* Homosexual equality

gen freehmsr = 6-freehms
lab var freehmsr	"Agree w gay/lesbian equality"


*** Create a set of dummies indicating 10-year age groups 
gen ag1 = 0
lab var ag1 "-25"
replace ag1 = 1 if agea < 25
replace ag1 = . if agea == . | agea == .a | agea == .d

gen ag2 = 0
lab var ag2 "25-34"
replace ag2 = 1 if agea >= 25 & agea < 35
replace ag2 = . if agea == . | agea == .a | agea == .d

gen ag3 = 0
lab var ag3 "35-44"
replace ag3 = 1 if agea >= 35 & agea < 45
replace ag3 = . if agea == . | agea == .a | agea == .d

gen ag4 = 0
lab var ag4 "40-49"
replace ag4 = 1 if agea >= 40 & agea < 50
replace ag4 = . if agea == . | agea == .a | agea == .d

gen ag5 = 0
lab var ag5 "45-54"
replace ag5 = 1 if agea >= 45 & agea < 55
replace ag5 = . if agea == . | agea == .a | agea == .d

gen ag6 = 0
lab var ag6 "55-64"
replace ag6 = 1 if agea >= 55 & agea < 65
replace ag6 = . if agea == . | agea == .a | agea == .d

gen ag7 = 0
lab var ag7 "65+"
replace ag7 = 1 if agea >= 65 & agea !=.
replace ag7 = . if agea == . | agea == .a | agea == .d

gen aggrp = .
replace aggrp = 1 if ag1==1
replace aggrp = 2 if ag2==1
replace aggrp = 3 if ag3==1
replace aggrp = 4 if ag5==1
replace aggrp = 5 if ag6==1
replace aggrp = 6 if ag7==1
replace aggrp = . if agea == . | agea == .a | agea == .d
lab var aggrp "Age group"
lab def aggrp 1 "-25" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+", replace
lab val aggrp aggrp
tab aggrp

*** Generate Oesch (2006) class variables *

* step 1: recode iscoco Occupation, ISCO88 (com) (waves 1-5)

iskooesch oescha16, isko(iscoco) emplrel(emplrel) emplno(emplno) sixteen replace
rename oesch16_oescha16 oescha16
label variable oescha16 "Oesch class position - 16 classes (w1-5)"
valtovar oescha16, display drop
replace oescha16=. if essround>5 
// note: emplrel exists for every case, so iskooesch generates class codes for those with missing iscoco but existing emplrel and emplno, basically higher managers from waves 6-9, but this is going to be problematic, because for waves 6-9 iscooesch needs to be used; the solution is to delete cases within the generated variable for waves 6-9; same logic applies for waves 6-9 but reversed

iskooesch oescha8, isko(iscoco) emplrel(emplrel) emplno(emplno) eight replace
rename oesch8_oescha8 oescha8
label variable oescha8 "Oesch class position - 8 classes (w1-5)"
valtovar oescha8, display drop
replace oescha8=. if essround>5

iskooesch oescha5, isko(iscoco) emplrel(emplrel) emplno(emplno) five replace
rename oesch5_oescha5 oescha5
label variable oescha5 "Oesch class position - 5 classes (w1-5)"
valtovar oescha5, display drop
replace oescha5=. if essround>5

* step 2: recode isco08 Occupation, ISCO08 (waves 6-10)

iscooesch oeschb16, isco(isco08) emplrel(emplrel) emplno(emplno) sixteen replace
rename oesch16_oeschb16 oeschb16
label variable oeschb16 "Oesch class position - 16 classes (w6-10)"
valtovar oeschb16, display drop
replace oeschb16=. if essround<6

iscooesch oeschb8, isco(isco08) emplrel(emplrel) emplno(emplno) eight replace
rename oesch8_oeschb8 oeschb8
label variable oeschb8 "Oesch class position - 8 classes (w6-10)"
valtovar oeschb8, display drop
replace oeschb8=. if essround<6

iscooesch oeschb5, isco(isco08) emplrel(emplrel) emplno(emplno) five replace
rename oesch5_oeschb5 oeschb5
label variable oeschb5 "Oesch class position - 5 classes (w6-10)"
valtovar oeschb5, display drop
replace oeschb5=. if essround<6

* step 3: create consolidated oesch class variable for all waves

bysort essround: sum oescha16
bysort essround: sum oeschb16
generate oesch16 = min(oescha16, oeschb16)
label variable oesch16 "Oesch class position - 16 classes"
label values oesch16 oescha16
valtovar oesch16, display
bysort essround: sum oesch16
tab oesch16

bysort essround: sum oescha8
bysort essround: sum oeschb8
generate oesch8 = min(oescha8, oeschb8)
label variable oesch8 "Oesch class position - 8 classes"
label values oesch8 oescha8
valtovar oesch8, display
bysort essround: sum oesch8
tab oesch8

bysort essround: sum oescha5
bysort essround: sum oeschb5
generate oesch5 = min(oescha5, oeschb5)
label variable oesch5 "Oesch class position - 5 classes"
label values oesch5 oescha5
valtovar oesch5, display
bysort essround: sum oesch5
tab oesch5

* Recode parents' education level 
/* Following the correspondence table on page 5, ESS5 Appandex 1, Education
https://stessrelpubprodwe.blob.core.windows.net/data/round5/survey/ESS5_appendix_a1_e04_2.pdf
The code above also follows this logic. Low includes lower secondary. 
Medium includes short tertiary, sometimes coded as tertiary. 
*/

* Recode father's education level
gen fedu = . 
replace fedu = 0 if edulvlfb < 300 
replace fedu = 1 if edulvlfb > 300 & edulvlfb < 600 
replace fedu = 2 if edulvlfb > 600 & edulvlfb < 900 
lab def fedu 0 "Father's education: Low" 1 "Father's education: Medium" 2 "Father's education: High", replace
lab val fedu fedu
lab var fedu "Father's education level"
tab edulvlfb fedu

* Recode mother's education level
gen medu = . 
replace medu = 0 if edulvlmb < 300 
replace medu = 1 if edulvlmb > 300 & edulvlmb < 600 
replace medu = 2 if edulvlmb > 600 & edulvlmb < 900 
lab def medu 0 "Mother's education: Low" 1 "Mother's education: Medium" 2 "Mother's education: High", replace
lab val medu medu
lab var medu "Mother's education level"
tab edulvlmb medu

* Recode financial difficulties variable 
recode fnsdfml (1 2 = 2) (3 = 1) (4 5 = 0), gen(fnsdfml3)
lab var fnsdfml3 "Severe financial difficulties in family when growing up" 
lab def fnsdfml3 0 "Childhood financial difficulties: Never or hardly ever", replace
lab def fnsdfml3 1 "Childhood financial difficulties: Sometimes", modify
lab def fnsdfml3 2 "Childhood financial difficulties: Always or often", modify
lab val fnsdfml3 fnsdfml3
tab fnsdfml fnsdfml3

* Recode left-right scale into dummy
// we remove those who didn't pick sides = 5
gen lrscale2=.
replace lrscale2 = 0 if lrscale < 5
replace lrscale2 = 1 if lrscale > 5
lab var lrscale2 "Left-right scale"
lab def lrscale2 0 "Left" 1 "Right"
lab val lrscale2 lrscale2

*** Relabel control variables
lab var eduyrs 		"Years of full-time education"
lab var agea 		"Age"

lab var impsafe		"Important: Safe surroundings"
lab var ipstrgv		"Important: Strong government"
lab var imptrad		"Important: Follow traditions"

lab var ipeqopt		"Important: People are treated equally"
lab var ipudrst		"Important: Understand different people"
lab var ipcrtiv		"Important: New ideas and creativity"

lab var ipeqopt 	"Important: People are treated equally"
lab var ipudrst 	"Important: Understand different people"
lab var ipcrtiv 	"Important: New ideas and creativity"

lab var lrscale 	"Placement on left-right scale (l/r)"
lab var stfhlth		"Satisfied with health system"


*** Dummies for Europe's Geographical Regions
gen north=0
replace north=1 if cntry=="DK" | cntry=="FI" | cntry=="IS" | cntry=="NO" | cntry=="SE"

gen south=0
replace south=1 if cntry=="CY" | cntry=="ES" | cntry=="GR" | cntry=="IT" | cntry=="PT"

gen east=0
replace east=1 if cntry=="BG" | cntry=="CZ" | cntry=="EE" | cntry=="HR" | cntry=="HU" | cntry=="LT" | cntry=="LV" | cntry=="PL" | cntry=="RO" | cntry=="SI" | cntry=="SK"

gen west=0
replace west=1 if cntry=="AT" | cntry=="BE" | cntry=="CH" | cntry=="DE" | cntry=="FR" | cntry=="GB" | cntry=="IE" | cntry=="LU" | cntry=="NL"

gen eurogeo=.
replace eurogeo = 1 if north==1
replace eurogeo = 2 if west==1 
replace eurogeo = 3 if south==1
replace eurogeo = 4 if east==1

lab def eurogeo 1 "North" 2 "West" 3 "South" 4 "East"
lab val eurogeo eurogeo


					* Split categorical variables
					* ===========================
**# Bookmark #5
		
					
/* These dummies are used to produce the descriptives tables, 
and are also needed to fit the structural equation models.
*/

tabulate hlth5, generate(hlth5tab)
lab var hlth5tab1 "Very bad"
lab var hlth5tab2 "Bad"
lab var hlth5tab3 "Fair"
lab var hlth5tab4 "Good"
lab var hlth5tab5 "Very good"

tab etfruit3, gen(etfruit3tab)
lab var etfruit3tab1 "At least 2-3 times a day"
lab var etfruit3tab2 "Once a day"
lab var etfruit3tab3 "Less than once a day"

tab eatveg3, gen(eatveg3tab)
lab var eatveg3tab1 "At least 2-3 times a day"
lab var eatveg3tab2 "Once a day"
lab var eatveg3tab3 "Less than once a day"

tab alcfreq3, gen(alcfreq3tab)
lab var alcfreq3tab1 "Less than once a month"
lab var alcfreq3tab2 "At least once a month"
lab var alcfreq3tab3 "Several times a week"

tab dosprt3, gen(dosprt3tab)
lab var dosprt3tab1 "At least six times a week"
lab var dosprt3tab2 "Twice or less a week"
lab var dosprt3tab3 "3-5 times a week"

tabulate domicil3, generate(domicil3tab)
lab var domicil3tab1 "Domicile: Big city or suburb"
lab var domicil3tab2 "Domicile: Small city"
lab var domicil3tab3 "Domicile: Village or farm"

tabulate mrtsts4, generate(mrtsts4tab)
lab var mrtsts4tab1 "Married or partnered"
lab var mrtsts4tab2 "Divorced or separated"
lab var mrtsts4tab3 "Widowed"
lab var mrtsts4tab4 "Never married or partnered"

lab var wrkctra "Type of work contract"
tab wrkctra, gen(wrkctratab)
lab var wrkctratab1 "Unlimited employment contract"
lab var wrkctratab2 "Limited employment contract"
lab var wrkctratab3 "No employment contract"

tab edulevel, gen(eduleveltab)
lab var eduleveltab1 "Low"
lab var eduleveltab2 "Medium"
lab var eduleveltab3 "High"

tab oesch5, gen(oesch5tab)
lab var oesch5tab1 "Class: Higher-grade service"
lab var oesch5tab2 "Class: Lower-grade service class"
lab var oesch5tab3 "Class: Small business owners"
lab var oesch5tab4 "Class: Skilled workers"
lab var oesch5tab5 "Class: Unskilled workers"

tab fnsdfml3, gen(fnsdfml3tab)
lab var fnsdfml3tab1 "Never or hardly ever"
lab var fnsdfml3tab2 "Sometimes"
lab var fnsdfml3tab3 "Always or often"

tab fedu, gen(fedutab)
lab var fedutab1 "Low"
lab var fedutab2 "Medium"
lab var fedutab3 "High"

tab medu, gen(medutab)
lab var medutab1 "Low"
lab var medutab2 "Medium"
lab var medutab3 "High"

tab emprf14, gen(emprf14tab)
lab var emprf14tab1 "Employee"
lab var emprf14tab2 "Self-employed"
lab var emprf14tab3 "Not working"
lab var emprf14tab4 "Father dead/absent"

tab emprm14, gen(emprm14tab)
lab var emprm14tab1 "Employee"
lab var emprm14tab2 "Self-employed"
lab var emprm14tab3 "Not working"
lab var emprm14tab4 "Mother dead/absent"

tab lknemny, gen(lknemnytab)
lab var lknemnytab1 "Not at all likely"
lab var lknemnytab2 "Not very likely"
lab var lknemnytab3 "Likely"
lab var lknemnytab4 "Very likely"

tab cntryc, gen(cntryc_)
tab essround, gen(essround_)


					* Standardize main variables
					* ==========================

			
** Set sample for standization
#delimit		;
global varlist 	migrr100 migrw100 health hlth2a agea gndr2 mrtsts4tab1 mrtsts4tab2 mrtsts4tab3 mrtsts4tab4 domicil3tab1 domicil3tab2 domicil3tab3 brncntr2 eduyrs oesch5tab1 oesch5tab2 oesch5tab3 oesch5tab4 oesch5tab5 hinctntb hincfel2 uempla hincsrc2a lrscale nwspol2 clsprty2 rlgdgr impsafe ipstrgv imptrad
				;
#delimit		cr

cap drop in_pols
qui: reg $varlist [aw=anweight]
gen in_pols = e(sample)

* Standardize

foreach i in $varlist {
		qui sum `i' [aw=anweight] if in_pols
		gen z_`i'=(`i'-r(mean))/r(sd)
}

* Copy labels
foreach var in $varlist { 
       local lbl : variable label `var' 
       label var z_`var' `"`lbl'"'
}

cap drop in_pols

					* Re-order variables
					* ==================

* Survey-related					
order essround year cntry cntryround cntryc atcntry atround idno id dweight pspwght pweight anweight

* Migration    
order imbgeco imbgecor imueclt imuecltr imwbcnt imwbcntr imsmetn imdfetn impcntr imwbcrm imrccon eimpcnt imtcjob imbleco imblecor imblecor2 imsclbn imsclbn2 imsclbn3 imsmrgt imrccon acetalv acetalv2 gvrfgap noimbro migr c_migr_m migrw2 migr100 migrw100 migrr100 c_migrw100_m c_migrw100_sd, a(anweight)

* Health 
order health hlthhmp hlth5 hlth2a hlth2b c_badhlth_pc hlthhmp2 stfhlth etfruit eatveg dosprt cgtsmke cgtsday alcfreq etfruit3 eatveg3 alcfreq3 dosprt3 alcbnge3 hlthbhv3 alcwkdy alcwknd alcbnge lknhlcn medtrun medtrunr medtrnp medtrnt medtroc medtrnl medtrwl medtrnaa medtroth medtrnu hltprhc hltprhb hltprbp hltpral hltprbn hltprpa hltprpf hltprsd hltprsc hltprsh hltprdi hltprnt hltphhc hltphhb hltphbp hltphal hltphbn hltphpa hltphpf hltphsd hltphsc hltphsh hltphdi hltphnt hltprca hltpsum hltprm2, a(migrw100)

* Trust
order stfhlthr trst trstr trstr2 trstplt trstpltr trstprl trstprlr trstlgl trstlglr ppltrst ppltrstr, a(c_migrw100_sd)

save data_hlthmigr/hlthmigr.dta, replace

